﻿using LayuiMvc.DataModel.Community;
using LayuiMvc.Logic.Community;
using LayuiMvcUtil.Result;
using Microsoft.AspNet.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace LayuiMvc.WebUI.Controllers
{
    public class UserController : Controller
    {
        /// <summary>
        /// 用户业务逻辑类
        /// </summary>
        private UserService userService = new UserService();
        /// <summary>
        /// 用户的个人信息
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        public async Task<ActionResult> UserCenter(int userId)
        {
            DataResult<UserCenterModel> rtnResult = await userService.UserCenterAsync(userId);
            return View(rtnResult);
        }

        #region 用户发布的帖子视图跳转
        /// <summary>
        /// 用户发布的帖子视图跳转
        /// </summary>
        /// <returns></returns>
        public ActionResult UserPublish()
        {
            return View();
        }

        /// <summary>
        /// 用户发布的帖子列表
        /// </summary>
        /// <param name="page">当前页索引</param>
        /// <param name="limit">每页的记录条数</param>
        /// <returns></returns>
        public async Task<ActionResult> UserPublishList(int page,int limit)
        {
            int userId = HttpContext.User.Identity.GetUserId<int>();
            DataResult<List<UserPublishModel>> rtnResult = await userService.UserPublishListAsync(userId, page, limit);
            return Json(rtnResult, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 用户收藏的帖子列表
        /// <summary>
        /// 用户收藏的帖子视图跳转
        /// </summary>
        /// <returns></returns>
        public ActionResult UserCollection()
        {
            return View();
        }


        /// <summary>
        /// 用户收藏的帖子列表
        /// </summary>
        /// <param name="page">当前页索引</param>
        /// <param name="limit">每页的记录条数</param>
        /// <returns></returns>
        public async Task<ActionResult> UserCollectionList(int page,int limit)
        {
            int userId = HttpContext.User.Identity.GetUserId<int>();
            DataResult<List<UserCollectionModel>> rtnResult = await userService.UserCollectionListAsync(userId, page, limit);
            return Json(rtnResult, JsonRequestBehavior.AllowGet);
        }

        #endregion
    }
}